package com.gitee.melin.bee.core.fs;

import com.gitee.melin.bee.core.jdbc.enums.DataSourceType;
import com.gitee.melin.bee.util.JsonUtils;
import lombok.Builder;
import lombok.Getter;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

@Getter
public class FsConnectionInfo {

    private DataSourceType dataSourceType;

    private String code;

    // 对象存储
    private String endpoint;

    private String region;

    private String accessKeyId;

    private String secretAccessKey;

    private String bucket;

    // ftp 认证
    private FTPProtocol protocol;

    private String host;

    private Integer port;

    private String user;

    private String password;

    // 基础路径
    private String basePath;

    // sftp keys 认证
    private String sshKeyFile;

    public FsConnectionInfo() {}

    @Builder(setterPrefix = "with")
    public FsConnectionInfo(
            DataSourceType dataSourceType,
            String code,
            String endpoint,
            String region,
            String accessKeyId,
            String secretAccessKey,
            String bucket,
            FTPProtocol protocol,
            String host,
            Integer port,
            String user,
            String password,
            String basePath,
            String sshKeyFile) {
        this.dataSourceType = dataSourceType;
        this.code = code;
        this.endpoint = endpoint;
        this.region = region;
        this.accessKeyId = accessKeyId;
        this.secretAccessKey = secretAccessKey;
        this.bucket = bucket;
        this.protocol = protocol;
        this.host = host;
        this.port = port;
        this.user = user;
        this.password = password;
        this.basePath = basePath;
        this.sshKeyFile = sshKeyFile;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        FsConnectionInfo that = (FsConnectionInfo) o;

        return new EqualsBuilder()
                .append(dataSourceType, that.dataSourceType)
                .append(code, that.code)
                .append(endpoint, that.endpoint)
                .append(region, that.region)
                .append(accessKeyId, that.accessKeyId)
                .append(secretAccessKey, that.secretAccessKey)
                .append(bucket, that.bucket)
                .append(protocol, that.protocol)
                .append(host, that.host)
                .append(port, that.port)
                .append(user, that.user)
                .append(password, that.password)
                .append(basePath, that.basePath)
                .append(sshKeyFile, that.sshKeyFile)
                .isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37)
                .append(dataSourceType)
                .append(code)
                .append(endpoint)
                .append(region)
                .append(accessKeyId)
                .append(secretAccessKey)
                .append(bucket)
                .append(protocol)
                .append(host)
                .append(port)
                .append(user)
                .append(password)
                .append(basePath)
                .append(sshKeyFile)
                .toHashCode();
    }

    @Override
    public String toString() {
        return JsonUtils.toJSONString(this);
    }
}
